package _21_多线程juc.demo01;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MyThread3_1 implements Callable<Integer> {

    private Integer tmp = 0;

    @Override
    public Integer call() throws Exception {
        System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());
        int sum = 0;
        for (int i = tmp; i < 10; i++) {
            sum += i;
        }
        return sum;
    }

    // 每十个数创建一个线程求和，返回最后和
    public static void main(String[] args) {
        MyThread3_1 thread = new MyThread3_1();
//        FutureTask<Integer> futureTask = new FutureTask<>(thread);
        for (int i = 0; i < 3; i++) {
            FutureTask<Integer> futureTask = new FutureTask<>(thread);
            new Thread(futureTask).start();
//            if (i % 10 == 0) {
//                new Thread(futureTask).start();
//            }
        }
//        try {
////            Integer sum = futureTask.get();
//            System.out.println(sum);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        } catch (ExecutionException e) {
//            throw new RuntimeException(e);
//        }

    }
}
